﻿#region Version Info
/* ========================================================================
* 【本类功能概述】
* 
* 作者：李荣楠
* 时间：2013-10-18 9:51:32
* 文件名：BaseConfig
* .net版本：4.0 
* ========================================================================
*/
#endregion
using System.Web;
using System.Xml;

namespace LCL.Config
{
    public class BaseConfig
    {
        /// <summary>
        /// 读base.config取配置文件
        /// </summary>
        /// <param name="Target"></param>
        /// <returns></returns>
        static internal string GetBaseValue(string Target)
        {
            return GetConfigValue(Target, "base");
        }
        /// <summary>
        /// 读DBconfig.config取配置文件
        /// </summary>
        /// <param name="Target"></param>
        /// <returns></returns>
        static internal string GetDBValue(string Target)
        {
            return GetConfigValue(Target, "DBconfig");
        }
        /// <summary>
        /// 读取config文件
        /// </summary>
        /// <param name="Target"></param>
        /// <param name="path"></param>
        /// <returns></returns>
        private static string GetConfigValue(string Target, string path)
        {
            string str = HttpContext.Current.Server.MapPath("~/config/"+path+".config");
            return GetConfigValue(Target, str, false);
        }
        /// <summary>
        /// 读取配置文件
        /// </summary>
        /// <param name="Target"></param>
        /// <param name="ConfigPathName"></param>
        /// <returns></returns>
       private  static  string GetConfigValue(string Target, string XmlPath, params bool[] cdata)
        {
            System.Xml.XmlDocument xdoc = new XmlDocument();
            xdoc.Load(XmlPath);
            XmlElement root = xdoc.DocumentElement;
            XmlNode node = root.SelectSingleNode(Target);
            if (node != null)
            {
                if (cdata != null && cdata[0])
                    return node.InnerText;
                else
                    return node.InnerXml;
            }
            else
            {
                return string.Empty;
            }
        }
    }
}
